package com.heavenick.core.monitor;

import java.util.HashMap;
import java.util.Map;

import org.aspectj.lang.ProceedingJoinPoint;

public class ThrowsMonitor {
	private static Map<String,Integer> map = new HashMap<String,Integer>();
	
	public Object around(ProceedingJoinPoint joinPoint){
		System.out.println(" into the ThrowsMonitor ");
		Object obj = null;
		try {
			obj = joinPoint.proceed();
		} catch (Throwable e) {
			if(map.get(joinPoint.getTarget().toString()) != null && map.get(joinPoint.getTarget().toString()).intValue() > 0)
				map.put(joinPoint.getTarget().toString(), map.get(joinPoint.getTarget().toString()).intValue()+1);
			else{
				map.put(joinPoint.getTarget().toString(), 1);
			}
			System.out.println(joinPoint.getTarget() + " throws exception count is : " + map.get(joinPoint.getTarget().toString()).intValue());
		}
		return obj;
	}

}